package presentation;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import bean.Card;
import bean.Hand;
import bean.Table;

public class Printer {
	private static final char[] SUIT_INDEX = { 'S', 'H', 'D', 'C' };
	private static final String SEAT_POSITION = "NESW";
	private static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

	public static void printCard(Card card) {
		if (!Card.isValid(card))
			System.out.print("Invalid Card!!");
		else
			System.out.print(card.toString());
	}

	public static void println(String x) {
		System.out.println(x);
	}

	public static String printNow() {
		Date starttime = new Date();

		System.out.println(dateFormat.format(starttime));
		return dateFormat.format(starttime);
	}

	public static void printHand(Hand hand) {
		System.out.print("Hand: ");
		if (hand == null || hand.getCards() == null)
			return;
		System.out.print(hand.toString());
	}

	public static void printTable(Table t) {
		println("Table: -------");
		if (t == null || t.getHands() == null)
			return;
		int i = 0;
		for (Hand h : t.getHands()) {
			System.out.print(SEAT_POSITION.charAt(i++) + "-");
			printHand(h);
			println("");
		}
		println("Lead: " + SEAT_POSITION.charAt(t.getLead()));
		println("trump: " + SUIT_INDEX[t.getTrump()]);
		println("--------------");
	}

	public static void printResult(Integer rs) {
		println("NS tricks = " + rs);
		println("EW tricks = " + (13 - rs));
	}
}
